// instanceof 是用来判断一个对象是否是一个类的实例

function Car() {
  this.run = 'running'
}

Bus.prototype = new Car()

function Bus() {
  this.name = 'su7'
}

let bus = new Bus()

console.log(bus instanceof Bus);    // true
console.log(bus instanceof Car);    // true
console.log(bus instanceof Object);  // true

console.log([1, 2, 3] instanceof Array);  // true
console.log([1, 2, 3] instanceof Object);  //true

function myinstanceof(L, R) {
  while (L !== null) {
    L = L.__proto__
    if (L === R.prototype) {
      return true
    }
  }

  return false
}

console.log(myinstanceof([1, 2, 3], Array));   // true
console.log(myinstanceof([1, 2, 3], Object));   // true

console.log(myinstanceof({ a: 1 }, Array));    // false




